home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-19 | 4.0 KB | 119 lines | [TEXT/CWIE] |
- (*
- Problem 04 - Text Processing
-
- const
- kMaxHandleSize = 1000000;
- const
- kActionMove = 1;
- kActionInsert = 2;
- kActionDelete = 3;
- kActionSearch = 4;
- kActionSearchAndReplace = 5;
- const
- kFlagCaseSensitiveBit = 0;
- kFlagGlobalBit = 1;
- kFlagBackwardsBit = 2;
- type
- ActionRecord = record
- action: UInt32;
- amount: SInt32;
- flags: UInt32;
- search: Str255;
- replace: Str255;
- end;
- ActionRecordArray = array[0..0] of ActionRecord;
- ActionRecordArrayPtr = ^ActionRecordArray;
-
- procedure TextProcess( data: Handle; action_count: UInt32; actions:
- ActionRecordArrayPtr );
-
- Given an unlocked handle to a block of text, you need to apply a sequence of
- actions to the data. You will be required to insert text, delete text, search
- for text, search for and replace text. All required actions take place at the
- position of the current selection pointer, which starts at zero, before the
- first character in the data. In response to each of the action commands you
- need to perform the following:
-
- kActionMove - move the internal position forward by the amount field (which may
- be negative). (Example, kActionMove with amount set to kMaxHandleSize will set
- the internal pointer to be GetHandleSize( data )).
-
- kActionInsert - Insert the replace string at the current location. (Example,
- if the internal pointer is GetHandleSize( data ), then the replace string will
- be appended to the handle.
-
- kActionDelete - Delete the number of characters specified by the amount field.
- The internal position pointer is never moved. If the amount field is greater
- than the number of characters after the internal pointer, then fewer characters
- are deleted such that the handle is truncated at the current value of the
- selection pointer.
-
- kActionSearch - search forward (backwards if the kFlagBackwardsBit is set in
- the flags field) for the search field (case sensitively if the
- kFlagCaseSenstitiveBit is set in the flags field). The position pointer should
- be set to point before the first character of the string if it is found, or at
- GetHandleSize (zero if backwards) if not found. If there is a match at the
- initial position, it is not counted (ie, kActionMove -kMaxHandleSize, kSearch
- 'hello', kSearch 'hello' finds the second occurance of 'hello').
-
- kActionSearchAndReplace - search forward (or backward if the kFlagBackwardsBit
- is set in the flags field), but when a match is found, replace it with the
- replace string, leaving the position pointer unmoved. If the kFlagGlobalBit is
- set in the flags field, continue searching as long matches continues to be
- found. Repeated searches begin after the previous replace string (i.e., never
- replace any characters of the replace string). For example, if you replace
- 'aaa' with 'ABA' (case insensitively) in 'aaaaaaaa' you will get 'ABAABAaa',
- not 'ABABABAa'. Replace never moves the internal position pointer.
-
- The internal selection pointer is constrained to be in the range of 0 and
- GetHandleSize(data), inclusive, at all times. Should any action cause the
- selection pointer to become less than zero (or greater than GetHandleSize),
- then you must reset it to zero (or GetHandleSize, respectively). The handle
- size will never exceed 1 Meg, and you will have plenty of memory to play with.
-
- Characters from chr(127)-chr(255) will never appear in the handle or any
- strings.
- *)
-
- unit Solution;
-
- interface
-
- // Do not modify the interface
-
- uses
- Types, Files;
-
- const
- kMaxHandleSize = 1000000;
- const
- kActionMove = 1;
- kActionInsert = 2;
- kActionDelete = 3;
- kActionSearch = 4;
- kActionSearchAndReplace = 5;
- const
- kFlagCaseSenstitiveBit = 0;
- kFlagGlobalBit = 1;
- kFlagBackwardsBit = 2;
- type
- ActionRecord = record
- action: UInt32;
- amount: SInt32;
- flags: UInt32;
- search: Str255;
- replace: Str255;
- end;
- ActionRecordArray = array[0..0] of ActionRecord;
- ActionRecordArrayPtr = ^ActionRecordArray;
-
- procedure TextProcess( data: Handle; action_count: UInt32; actions: ActionRecordArrayPtr );
-
- implementation
-
- // Fill in your solution and then submit this folder
-
- // Team Name: FILL IN YOUR TEAM NAME!
-
- end.
-